//
//  COMineHTTP.swift
//  CocoProject
//
//  Created by Ruthless on 2023/8/29.
//

import UIKit
import Moya

let mineProvider = MoyaProvider<COMineHTTP>()
enum COMineHTTP {
    case qaList(page: Int)
    case sqList(page: Int)
    case logout
    case delete
}

extension COMineHTTP: TargetType {
    var path: String {
        switch self {
        case .qaList:
            return "/coco/coco589/square/q0002/my/page"
        case .sqList:
            return "/coco/coco589/square/q0002/my/002"
        case .logout:
            return "/coco/coco589/login/out"
        case .delete:
            return "/coco/coco589/user/delete"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .qaList:
            return .post
        case .sqList:
            return .post
        case .logout:
            return .get
        case .delete:
            return .get
        }
    }
    
    var task: Moya.Task {
        var params: [String: Any] = [:]
        switch self {
        case .qaList(let page):
            params["pagNum"] = page
            params["pagSize"] = 20
        case .sqList(let page):
            params["pagNum"] = page
            params["pagSize"] = 20
        case .logout:
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        case .delete:
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        }
        
        return .requestParameters(parameters: params, encoding: JSONEncoding.default)
    }
    
    
    var headers: [String : String]? {
        var params: [String: String] = [:]
        params["AVS"] = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
        params["OSB"] = "1"
        params["AGKB"] = "H1"
        params["token"] = COUserManager.userInfo?.token
        return params
    }
}
